﻿using NUnit.Framework;

namespace MC.EventHandler.Install.Tests
{
    [TestFixture]
    public class InstallationConfigurationTests
    {
        [Test]
        public void ReadArguments()
        {
            var localhost = "localhost";
            var adminDbUsername = "adminDbUsername";
            var adminDbPassword = "adminDbPassword";
            var appDbUsername = "appDbUsername";
            var appDbPassword = "appDbPassword";
            var dbName = "dbName";
            var appAdminUsername = "appAdminUsername";
            var virtualDirectoryName = "/";
            var appAdminPassword = "appAdminPassword";
            var webDirectory = @"C:\Temp";

            InstallationConfiguration config = CreateConfigurationObject(localhost, adminDbUsername, adminDbPassword, appDbUsername, appDbPassword, dbName, appAdminUsername, appAdminPassword, virtualDirectoryName, webDirectory);

            Assert.IsNotNull(config);
            Assert.AreEqual(localhost, config.SQLServer);
            Assert.AreEqual(adminDbUsername, config.AdminDbUsername);
            Assert.AreEqual(adminDbPassword, config.AdminDbPassword);
            Assert.AreEqual(appDbUsername, config.AppDbUsername);
            Assert.AreEqual(appDbPassword, config.AppDbPassword);
            Assert.AreEqual(dbName, config.DBName);
            Assert.AreEqual(appAdminUsername, config.AppAdminUsername);
            Assert.AreEqual(appAdminPassword, config.AppAdminPassword);
            Assert.AreEqual(virtualDirectoryName, config.VirtualDirectoryName);
            Assert.AreEqual(virtualDirectoryName, config.VirtualDirectoryName);
        }

        [Test]
        public void TestEmptyProperties()
        {

            var localhost = "localhost";
            var adminDbUsername = "adminDbUsername";
            var adminDbPassword = "adminDbPassword";
            var appDbUsername = "appDbUsername";
            var appDbPassword = "appDbPassword";
            var dbName = "dbName";
            var appAdminUsername = "appAdminUsername";
            var virtualDirectoryName = "";
            var appAdminPassword = "appAdminPassword";
            var webDirectory = @"C:\Temp";

            InstallationConfiguration config = CreateConfigurationObject(localhost, adminDbUsername, adminDbPassword, appDbUsername, appDbPassword, dbName, appAdminUsername, appAdminPassword, virtualDirectoryName, webDirectory);

            Assert.IsTrue(config.AnyRequiredValuesBlank());
        }

        [Test]
        public void TestEmptyProperties2()
        {

            var localhost = "localhost";
            var adminDbUsername = "adminDbUsername";
            var adminDbPassword = "adminDbPassword";
            var appDbUsername = "appDbUsername";
            var appDbPassword = "appDbPassword";
            var dbName = "dbName";
            var appAdminUsername = "appAdminUsername";
            var virtualDirectoryName = "/";
            var appAdminPassword = "appAdminPassword";
            var webDirectory = @"C:\Temp";

            InstallationConfiguration config = CreateConfigurationObject(localhost, adminDbUsername, adminDbPassword, appDbUsername, appDbPassword, dbName, appAdminUsername, appAdminPassword, virtualDirectoryName, webDirectory);

            Assert.IsFalse(config.AnyRequiredValuesBlank());
        }

        private static InstallationConfiguration CreateConfigurationObject(string localhost, string adminDbUsername, string adminDbPassword, string appDbUsername, string appDbPassword, string dbName, string appAdminUsername, string appAdminPassword, string virtualDirectoryName, string webDirectory)
        {
            string[] args = new[]
                {
                    "/SQLServer", localhost,
                    "/TestData",
                    "/AdminDbUsername", adminDbUsername,
                    "/AdminDbPassword", adminDbPassword,
                    "/AppDbUsername", appDbUsername,
                    "/AppDbPassword", appDbPassword,
                    "/DBName", dbName,
                    "/AppAdminUsername", appAdminUsername,
                    "/AppAdminPassword", appAdminPassword,
                    "/VirtualDirectoryName", virtualDirectoryName,
                    "/NewWebApplication",
                    "/SMTPHost", localhost,
                    "/WebDirectory", webDirectory
                };
            return InstallationConfiguration.Parse(args);
        }
    }
}
